package com.hmall.mq;

import com.alibaba.fastjson.JSON;
import com.hmall.common.dto.Item;
import com.hmall.pojo.ItemDoc;
import com.hmall.service.HmallService;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class HmallListener {
    @Autowired
    private HmallService hmallService;
    /**
     * 监听新增业务
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "hmall1.insert.queue"),
            exchange = @Exchange(name = "hmall1.topic",type = ExchangeTypes.TOPIC),
            key = "hmall1.insert.fanout"
    ))
    public void listernHmallInsert(Long id){
       hmallService.insertMqById(id);
    }
    /**
     * 删除业务监听
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "hamll1.delete.queue"),
            exchange = @Exchange(name = "hmall1.topic",type = ExchangeTypes.TOPIC),
            key = "hmall1.delete.fanout"
    ))
    @RabbitListener(queues = "hmall1.queue1")
    public void listernHmallDelete(Long id){
        hmallService.deleteMqById(id);
    }
}   
